var g_var = {
    fb_permissions: 'offline_access, email, user_checkins, user_location, user_activities, read_friendlists, publish_stream',
    fb_login_button: "#facebook_login",
    fb_join_button : "#facebook_join"
};

window.fbAsyncInit = function() {

    FB.init({
        appId      : '277436492298031',
        channelUrl : '//fitwow.com/index/channel',
        status     : true,
        cookie     : true,
        xfbml      : true,
        oauth      : true
        });
};


function fb_init(d, callback)
{
    //var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
    //js = d.createElement('script'); js.id = id; js.async = true;
    //js.src = document.location.protocol + "//connect.facebook.net/en_US/all.js";
    //d.getElementsByTagName('head')[0].appendChild(js);
    //

    $(g_var.fb_login_button).click(function(){
        FB.login(callback, {scope: g_var.fb_permissions});
    });
    
    $(g_var.fb_join_button).click(function(){
        FB.login(callback, {scope: g_var.fb_permissions});
    });
}

function fb_init2(d)
{
    var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
    js = d.createElement('script'); js.id = id; js.async = true;
    js.src = document.location.protocol + "//connect.facebook.net/en_US/all.js";
    d.getElementsByTagName('head')[0].appendChild(js);
}

function fb_check_login(callback)
{
    FB.getLoginStatus(callback);
}

function fb_getinfo(callback)
{
    FB.api('/me', callback);
}

function fb_get_friendlists(callback)
{
    FB.api('/me/friends?access_token='+$.cookie("access_token"), callback);
}

function fb_publish_feed(user, msg, callback)
{ 
    FB.api("/"+user+"/feed?access_token="+$.cookie("access_token"), 'post', msg, callback);
}
